//
//  OSCBottomBarViewModel.m
//  OSChina
//
//  Created by 8b410-2 on 17/1/5.
//  Copyright © 2017年 abb. All rights reserved.
//

#import "OSCBottomBarViewModel.h"
#import "OSCBaseTableViewModel.h"
#import "OSCCommentTools.h"
@interface OSCBottomBarViewModel ()

@property (nonatomic, strong, readwrite) OSCBaseViewModel *childViewModel;

@end

@implementation OSCBottomBarViewModel

- (instancetype)initWithServices:(id<OSCViewModelServices>)services params:(NSDictionary *)params {
    self = [super initWithServices:services params:params];
    if (self) {
        self.childViewModel = params[@"childViewModel"];
    }
    return self;
}

- (void)initialize {
    [super initialize];
    
    self.requestPubCommentCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
        return [[OSCCommentTools requestPubCommentWithParamsModel:self.pubCommentParams]
                takeUntil:self.rac_willDeallocSignal];
    }];
    [self.requestPubCommentCommand.executionSignals.switchToLatest subscribeNext:^(NSString *resultString) {
        self.commentViewAttribute = nil;
        if ([self.childViewModel isKindOfClass:[OSCBaseTableViewModel class]]) {
            OSCBaseTableViewModel *tableViewModel = (OSCBaseTableViewModel *)self.childViewModel;
            [tableViewModel.needRefresh sendNext:@(YES)];
        }
        // TODO: - 显示HUD
    }];
}

@end
